package com.dianganjiao.lib.base

import android.os.Build
import android.view.View
import android.widget.TextView
import androidx.annotation.RequiresApi
import com.dianganjiao.lib.R
import com.dianganjiao.lib.util.ViewUtil
import com.dianganjiao.lib.wiget.IconTextView

abstract class AbsTitleActivity : AbsActivity() {

    @RequiresApi(Build.VERSION_CODES.HONEYCOMB)
    override fun getContainerView(layoutId: Int): View {
        return ViewUtil.addTitle(View.inflate(this,layoutId,null))
    }

    override fun onCreateViewChanged() {
        setOnTitleBackClickListener()
        findViewById<TextView>(R.id.activity_title_id)
            .text = getPageTitle()
        onCreateChanged()
    }

    open fun setOnTitleBackClickListener(){
        findViewById<IconTextView>(R.id.activity_back_layout_id)
            .setOnClickListener { finish() }
    }

    abstract fun onCreateChanged()

    fun setPageTitle(title:String){
        findViewById<TextView>(R.id.activity_title_id)
            .text = title
    }

    abstract fun getPageTitle():String
}